﻿//415.字符串相加
char* addStrings(char* num1, char* num2) {
    int n = strlen(num1) - 1, m = strlen(num2) - 1, count = 0, size = 0;
    char* ans = (char*)malloc(sizeof(char) * (fmax(n, m) + 3));

    while (n >= 0 || m >= 0)
    {
        int x = n < 0 ? 0 : num1[n] - '0';
        int y = m < 0 ? 0 : num2[m] - '0';
        int temp = (x + y + count) % 10;
        count = (x + y + count) / 10;
        ans[size++] = temp + '0';
        n--;
        m--;
    }

    if (count != 0)
    {
        ans[size++] = count + '0';
    }
    ans[size] = '\0';

    int l = 0, r = size - 1;
    while (l < r)
    {
        char temp = ans[l];
        ans[l] = ans[r];
        ans[r] = temp;
        l++;
        r--;
    }
    return ans;
}